using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using Presentation;
using Presentation.Contracts;

namespace ProjektZespolowy.Forum
	{
	public partial class AddComment : System.Web.UI.Page, IAddCommentView
		{
		private AddCommentPresenter presenter;


		protected override void OnInit(EventArgs e)
			{
			base.OnInit(e);
			presenter = new AddCommentPresenter(this);
	
			}

		protected void Page_Load(object sender, EventArgs e)
			{
			if (!IsPostBack)
				{
				if (this.LoggedUserID < 0)
					{
					Response.Redirect("~/Default.aspx");
					}
				if (!string.IsNullOrEmpty(Request.QueryString["ForumID"]))
					ViewState["ForumID"] = Request.QueryString["ForumID"];
				if (!string.IsNullOrEmpty(Request.QueryString["ParentCommentID"]))
					ViewState["ParentCommentID"] = Request.QueryString["ParentCommentID"];
				if (!string.IsNullOrEmpty(Request.QueryString["ReplyID"]))
					{
					ViewState["ReplyID"] = Request.QueryString["ReplyID"];
					this.replyContentTextBox.Visible = true;
					this.quotationLabel.Visible = true;
					}

				presenter.Initialize();
				}
				
			}

		protected void newTopicButton_Click(object sender, EventArgs e)
			{
			presenter.AddComment();
			Response.Redirect("~/Forum/ShowForum.aspx?ForumID=" + this.ForumID.ToString() + "&ParentCommentID=" + this.ParentCommentID.ToString());
			}

		#region IAddCommentView Members

		public int ForumID
			{
			get
				{
				if (ViewState["ForumID"] != null)
					return Int32.Parse((string)ViewState["ForumID"]);
				else
					return -1;
				}
			}

		public int ParentCommentID
			{
			get
				{
				if (ViewState["ParentCommentID"] != null)
					return Int32.Parse((string)ViewState["ParentCommentID"]);
				else
					return -1;
				}
			}

		public int ReplyID
			{
			get 
				{
				if (ViewState["ReplyID"] != null)
					return Int32.Parse((string)ViewState["ReplyID"]);
				else
					return -1;
				} 
			}

		public string ReplyContent
			{
			set { this.replyContentTextBox.Text = value; }
			get { return this.replyContentTextBox.Text; }
			}

		public string CommentContent
			{
			get { return this.contentCommentTextBox.Text; }
			}

		#endregion

		#region IUserAuthView Members

		public int LoggedUserID
			{
			get
				{
				if (Session[Globals.ContentNamesGlobals.SessionWithUserId] != null)
					return Int32.Parse(Session[Globals.ContentNamesGlobals.SessionWithUserId].ToString());
				else
					return -1;
				}
			}

		#endregion

		}
	}
